//
//  PrePayTypeTool.m
//  预购清单
//
//  Created by liujianlong on 2022/10/17.
//

#import "PrePayTypeTool.h"

@implementation PrePayTypeTool
+ (void)find:(NSString*)account complete:(nullable void(^) (NSMutableArray <PrepayType *>*result))block{
    NSString* where = [NSString stringWithFormat:@"where %@=%@",bg_sqlKey(@"account"),bg_sqlValue(account)];
    NSInteger cout = [PrepayType bg_count:nil where:where];
    [PrepayType bg_findAsync:nil where:where complete:^(NSArray * _Nullable array) {
        dispatch_async(dispatch_get_main_queue(), ^{
            if (block) {
                block([NSMutableArray arrayWithArray:array]);
            }
        });
    }];
}
+ (void)delete:(PrepayType*)type complete:(nullable void(^) (void))block{
    NSString* where = [NSString stringWithFormat:@"where %@=%@ and %@=%@",bg_sqlKey(@"account"),bg_sqlValue(type.account),bg_sqlKey(@"name"),bg_sqlValue(type.name)];
    NSInteger count = [User bg_count:nil where:where];
    if (count <= 0) {
       
    }
    [PrepayType bg_deleteAsync:nil where:where complete:^(BOOL isSuccess) {
        dispatch_async(dispatch_get_main_queue(), ^{
            if (isSuccess){
                if (block) { return block();}
            }else{}
        });
    }];
}
@end
